package com.no1ikun.view;

import com.no1ikun.publicdb.DB;
import com.no1ikun.util.MyButton;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LeftJPanel extends JPanel  implements ActionListener {
    private MyButton index;
    private MyButton insert;
    private MyButton update;
    private MyButton select;
    private MyButton delete;
    private MyButton punishment;
    private MyButton motive;

    public LeftJPanel() {
        init();
    }

    public void init() {
        this.setLayout(null);//绝对布局
//        this.setBackground(new Color(8, 27, 42));
        this.setBounds(0, 70, 60, 600);
        this.setOpaque(false);
        this.setLayout(new FlowLayout(FlowLayout.LEADING,0,10));
        Dimension navDimension = new Dimension(60,60);
        Image img ;
        ImageIcon image ;
        Color buttoncolor = new Color(210, 250, 253);

        index = new MyButton("首页数据", 0, 0, 0, 0, buttoncolor, null);
        index.setFont(new Font("微软雅黑",1,0));
        index.setPreferredSize(navDimension);
        image = new ImageIcon(getClass().getResource("../img/meun.png"));
        img = image.getImage();
        img = img.getScaledInstance(20,20, Image.SCALE_DEFAULT);
        image.setImage(img);
        index.setIcon(image);

        insert = new MyButton("学生添加", 0, 0, 60, 60, buttoncolor, null);
        insert.setFont(new Font("微软雅黑",1,0));
        insert.setPreferredSize(navDimension);
        image = new ImageIcon(getClass().getResource("../img/add.png"));
        img = image.getImage();
        img = img.getScaledInstance(20,20, Image.SCALE_DEFAULT);
        image.setImage(img);
        insert.setIcon(image);

        update = new MyButton("学生修改", 0, 0, 60, 60, buttoncolor, null);
        update.setFont(new Font("微软雅黑",1,0));
        update.setPreferredSize(navDimension);
        image = new ImageIcon(getClass().getResource("../img/alter.png"));
        img = image.getImage();
        img = img.getScaledInstance(20,20, Image.SCALE_DEFAULT);
        image.setImage(img);
        update.setIcon(image);


        select = new MyButton("学生查询", 0, 0, 60, 60, buttoncolor, null);
        select.setFont(new Font("微软雅黑",1,0));
        select.setPreferredSize(navDimension);
        image = new ImageIcon(getClass().getResource("../img/select.png"));
        img = image.getImage();
        img = img.getScaledInstance(20,20, Image.SCALE_DEFAULT);
        image.setImage(img);
        select.setIcon(image);



        delete = new MyButton("学生删除", 0, 0, 60, 60, buttoncolor, null);
        delete.setFont(new Font("微软雅黑",1,0));
        delete.setPreferredSize(navDimension);
        image = new ImageIcon(getClass().getResource("../img/del.png"));
        img = image.getImage();
        img = img.getScaledInstance(20,20, Image.SCALE_DEFAULT);
        image.setImage(img);
        delete.setIcon(image);



        punishment = new MyButton("学生奖惩", 0, 0, 60, 60, buttoncolor, null);
        punishment.setFont(new Font("微软雅黑",1,0));
        punishment.setPreferredSize(navDimension);
        image = new ImageIcon(getClass().getResource("../img/rewards.png"));
        img = image.getImage();
        img = img.getScaledInstance(25,25, Image.SCALE_DEFAULT);
        image.setImage(img);
        punishment.setIcon(image);




        this.add(index);
        this.add(insert);
        this.add(update);
        this.add(select);
        this.add(delete);
        this.add(punishment);


        //给按钮绑定监听事件
        index.addActionListener(this);
        insert.addActionListener(this);
        update.addActionListener(this);
        select.addActionListener(this);
        delete.addActionListener(this);
        punishment.addActionListener(this);


    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String ss = e.getActionCommand();

        switch (ss){
            case "首页数据":
                DB.mainView.showPage("index");

                break;
            case "学生添加":
                DB.mainView.showPage("insert");
                break;
            case "学生修改":
                DB.mainView.showPage("update");
                break;
            case "学生删除":
                DB.mainView.showPage("delete");
                break;
            case "学生查询":
                DB.mainView.showPage("select");
                break;
            case "学生奖惩":
                DB.mainView.showPage("punishment");
                break;
        }

    }

}
